package com.cds.alert.action;

import java.io.IOException;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.cds.alert.common.mybatis.Page;
import com.cds.alert.ibatis.Criteria;
import com.cds.alert.pojo.AlertAlarmSession;
import com.cds.alert.service.AlertAlarmSessionService;
import com.opensymphony.xwork2.Preparable;

public class AlertAlarmSessionAction extends BaseAction implements Preparable {
	private static final long serialVersionUID = 6776558938712115191L;
	private List<AlertAlarmSession> alertAlarmSessions;
	private AlertAlarmSession alertAlarmSession;
	private Long id;
	private Page<AlertAlarmSession> page = new Page<AlertAlarmSession>(5);// 每页5条记录
	@Autowired
	private AlertAlarmSessionService alertAlarmSessionService;

	private Integer maxLength = 3;

	public void prepare() {
		if (getRequest().getMethod().equalsIgnoreCase("post")
				&& (!"".equals(getRequest()
						.getParameter("alertAlarmSession.id")))) {
			// alertAlarmSession =
			// alertAlarmSessionService.selectByPrimaryKey(id);
		}
	}

	public List<AlertAlarmSession> getAlertAlarmSessions() {
		return alertAlarmSessions;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public AlertAlarmSession getAlertAlarmSession() {
		return alertAlarmSession;
	}

	public void setAlertAlarmSession(AlertAlarmSession alertAlarmSession) {
		this.alertAlarmSession = alertAlarmSession;
	}

	public String delete() {

		return SUCCESS;
	}

	public String edit() throws IOException {

		return SUCCESS;
	}

	public String execute() {
		return SUCCESS;
	}

	public String cancel() {
		if (!"list".equals(from)) {
			return "home";
		}
		return "cancel";
	}

	public String save() throws Exception {
		return SUCCESS;
	}

	public String list() {
		Criteria criteria = new Criteria();
		String read = this.getRequest().getParameter("read");
		if (StringUtils.isBlank(read)) {
			criteria.put("read", 1);// 标记为已读
		}

		alertAlarmSessions = alertAlarmSessionService.queryByExample(criteria);
		return SUCCESS;
	}
}
